package ssm.controller;

import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import ssm.pojo.Employee;
import ssm.service.EmployeeService;

import java.util.List;

@Controller
public class EmployeeController {
    @Autowired
    EmployeeService employeeService;

    //查询所有员工信息-->/employee-->get
    @RequestMapping(value = "/employee",method = RequestMethod.GET)
    public String getAllEmployee(Model model) {
        List<Employee> list = employeeService.getAllEmployee();
//        共享到域对象中
        model.addAttribute("list",list);
//        跳转到页面
        return "employee_list";
    }

    //查询员工的分页信息-->/employee/page/1-->get
    @RequestMapping(value = "/employee/page/{pageNum}", method = RequestMethod.GET)
    public String getEmployeePage(@PathVariable("pageNum") Integer pageNum,Model model){
//        获取员工分页数据
        PageInfo<Employee> pageInfo = employeeService.getEmployeePage(pageNum);
//        分页数据共享到请求中
        model.addAttribute("page",pageInfo);
//        跳转到employee_list.html
        return "employee_list";
    }

//根据id查询员工信息-->/employee/1-->get

//跳转到添加页面-->/to/add-->get

//添加员工信息-->/employee-->post

//修改员工信息-->/employee-->put

//删除员工信息-->/employee-->delete

}
